import typing
from typing import List as typing_list
from typing import Generic
from math import sqrt, log, pi, cos, sin
from random import random

Array = typing_list
T = typing.TypeVar('T')


def zero_array(l, length):
    return [item for item in builtin_range(length)]


def resize_array(l, new_length, old_length):
    for i in builtin_range(old_length, new_length):
        l.append(0)


class List(Generic[T]):
    length: int
    max_length: int
    data: Array[T] = [0]

    def __init__(self):
        self.length = 0
        self.max_length = 10
        data: Array[T] = zero_array(self.data, self.max_length)
        self.data = data

    def append(self, x: T) -> int:
        self.data[self.length] = x
        self.length = self.length + 1
        if self.length >= 0.6 * self.max_length:
            resize_array(self.data, self.max_length * 2 * 8, self.max_length * 8)
            self.max_length = self.max_length * 2
            return 0
        return 0

    def __setitem__(self, key: int, value: T) -> int:
        self.data[key] = value
        return 0

    def __getitem__(self, key: int) -> T:
        return self.data[key]


class Agent:
    id: int

    def __init__(self, agent_id: int):
        self.id = agent_id


class AgentList(Generic[T]):
    agents: List[T]

    def __init__(self):
        a: List[T] = List()
        self.agents = a

    def add(self, agent: T) -> int:
        agents: List[T] = self.agents
        agents.append(agent)
        return 0

    def __getitem__(self, key: int) -> T:
        return self.agents[key]


def normal(mu: float, sigma: float) -> float:
    u1: float = random()
    u2: float = random()
    r: float = sqrt(-2 * log(u1))
    theta: float = 2 * 3.1415927 * u2
    z1: float = r * sin(theta)
    return z1 * sigma + mu


class RangeIterator:
    counter: int
    end: int

    def __init__(self, end: int):
        self.counter = -1
        self.end = end - 1

    def __next__(self) -> int:
        self.counter = self.counter + 1
        return self.counter

    def __stop__(self) -> int:
        if self.counter >= self.end:
            return 1
        else:
            return 0


builtin_range = range


def range(n: int) -> RangeIterator:
    return RangeIterator(n)
